﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.core {
    import reprise.ui.*;
    import reprise.controls.*;
    import reprise.ui.renderers.*;
    import reprise.controls.html.*;

    public class UIRendererFactory {

        protected var m_tagHandlers:Object;
        protected var m_inputTypeHandlers:Object;
        protected var m_defaultBorderRenderer:Class;
        protected var m_tooltipRenderers:Object;
        protected var m_defaultBackgroundRenderer:Class;
        protected var m_classHandlers:Object;
        protected var m_backgroundRenderers:Object;
        protected var m_borderRenderers:Object;
        protected var m_idHandlers:Object;
        protected var m_defaultTooltipRenderer:Class;

        public static var TEXTNODE_TAGS:String = "span,br,strong,i,null,";

        public function UIRendererFactory(){
            m_idHandlers = {};
            m_classHandlers = {};
            m_tagHandlers = {};
            m_inputTypeHandlers = {};
            m_borderRenderers = {};
            m_backgroundRenderers = {};
            m_tooltipRenderers = {};
            registerDefaultRenderers();
        }
        public function registerIdRenderer(_arg1:String, _arg2:Class):void{
            m_idHandlers[_arg1.toLowerCase()] = _arg2;
        }
        public function registerTooltipRenderer(_arg1:String, _arg2:Class):void{
            m_tooltipRenderers[_arg1.toLowerCase()] = _arg2;
        }
        public function rendererByTag(_arg1:String):UIComponent{
            var _local2:Class = m_tagHandlers[_arg1.toLowerCase()];
            if (!_local2){
                return (null);
            };
            return (UIComponent(new (_local2)));
        }
        public function borderRendererById(_arg1:String):ICSSRenderer{
            var _local2:Class = m_borderRenderers[((_arg1) || ("")).toLowerCase()];
            if (_local2 == null){
                _local2 = m_defaultBorderRenderer;
            };
            var _local3:ICSSRenderer = new (_local2);
            _local3.setId(_arg1);
            return (_local3);
        }
        public function backgroundRendererById(_arg1:String):ICSSRenderer{
            var _local2:Class = m_backgroundRenderers[((_arg1) || ("")).toLowerCase()];
            if (_local2 == null){
                _local2 = m_defaultBackgroundRenderer;
            };
            var _local3:ICSSRenderer = new (_local2);
            _local3.setId(_arg1);
            return (_local3);
        }
        public function rendererByInputType(_arg1:String):UIComponent{
            var _local2:Class = m_inputTypeHandlers[_arg1.toLowerCase()];
            if (!_local2){
                return (null);
            };
            return (UIComponent(new (_local2)));
        }
        public function registerDefaultBorderRenderer(_arg1:Class):void{
            m_defaultBorderRenderer = _arg1;
        }
        public function registerDefaultBackgroundRenderer(_arg1:Class):void{
            m_defaultBackgroundRenderer = _arg1;
        }
        public function registerBorderRenderer(_arg1:String, _arg2:Class):void{
            m_borderRenderers[_arg1.toLowerCase()] = _arg2;
        }
        public function registerBackgroundRenderer(_arg1:String, _arg2:Class):void{
            m_backgroundRenderers[_arg1.toLowerCase()] = _arg2;
        }
        public function tooltipRendererById(_arg1:String):AbstractTooltip{
            if (_arg1 == null){
                return (new m_defaultTooltipRenderer());
            };
            var _local2:Class = m_tooltipRenderers[_arg1.toLowerCase()];
            if (_local2 == null){
                _local2 = m_defaultTooltipRenderer;
            };
            return (new (_local2));
        }
        protected function registerDefaultRenderers():Boolean{
            m_defaultBorderRenderer = DefaultBorderRenderer;
            m_defaultBackgroundRenderer = DefaultBackgroundRenderer;
            m_defaultTooltipRenderer = DefaultTooltipRenderer;
            registerTagRenderer("p", Label);
            registerTagRenderer("h1", Label);
            registerTagRenderer("h2", Label);
            registerTagRenderer("h3", Label);
            registerTagRenderer("h4", Label);
            registerTagRenderer("h5", Label);
            registerTagRenderer("h6", Label);
            registerTagRenderer("div", UIComponent);
            registerTagRenderer("hr", UIComponent);
            registerTagRenderer("img", Image);
            return (true);
        }
        public function registerTagRenderer(_arg1:String, _arg2:Class):void{
            m_tagHandlers[_arg1.toLowerCase()] = _arg2;
        }
        public function rendererByNode(_arg1:XML):UIComponent{
            var _local2:UIComponent;
            var _local6:String;
            var _local7:Array;
            var _local8:int;
            var _local9:String;
            if (_arg1.nodeKind() == "text"){
                return (rendererByTag("p"));
            };
            var _local3:String = _arg1.@id.toString();
            if (_local3){
                _local2 = rendererById(_local3);
                if (_local2){
                    return (_local2);
                };
            };
            var _local4:XMLList = _arg1.@["class"];
            if (_local4.length()){
                _local6 = _local4[0];
                if (_local6){
                    _local7 = _local6.split(" ");
                    _local8 = _local7.length;
                    while (_local8--) {
                        _local9 = String(_local7[_local8]);
                        _local2 = rendererByClass(_local9);
                        if (_local2){
                            return (_local2);
                        };
                    };
                };
            };
            var _local5:String = (_arg1.localName() as String);
            if (_local5 == "input"){
                _local2 = rendererByInputType(_arg1.@type[0]);
                if (_local2){
                    return (_local2);
                };
            };
            _local2 = rendererByTag(_local5);
            return (_local2);
        }
        public function registerDefaultTooltipRenderer(_arg1:Class):void{
            m_defaultTooltipRenderer = _arg1;
        }
        public function registerInputTypeRenderer(_arg1:String, _arg2:Class):void{
            m_inputTypeHandlers[_arg1.toLowerCase()] = _arg2;
        }
        public function rendererByClass(_arg1:String):UIComponent{
            var _local2:Class = m_classHandlers[_arg1.toLowerCase()];
            if (!_local2){
                return (null);
            };
            return (UIComponent(new (_local2)));
        }
        public function rendererById(_arg1:String):UIComponent{
            var _local2:Class = m_idHandlers[_arg1.toLowerCase()];
            if (!_local2){
                return (null);
            };
            return (UIComponent(new (_local2)));
        }
        public function registerClassRenderer(_arg1:String, _arg2:Class):void{
            _arg1 = _arg1.toLowerCase();
            m_classHandlers[_arg1.toLowerCase()] = _arg2;
        }

    }
}//package reprise.core 
